//
//  CedarBaseViewController.m
//  CedarSuperCloud
//
//  Created by lshenrong on 2017/11/24.
//  Copyright © 2017年 cedarhd. All rights reserved.
//

#import "CedarBaseViewController.h"

@interface CedarBaseViewController ()<UITextViewDelegate>

@property (nonatomic, strong) UIImageView *noContentImgV;
@property (nonatomic, strong) UILabel *tipLabel;
@property (nonatomic,strong) UITextView *statusTextView;


@end

@implementation CedarBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    self.view.backgroundColor = kAppBackgoundColor;
    self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];;
    //[self setLeftBarButton];
    if ([self.removeControllerNameArray count]>0 ) {//有需要移除的控制器
#if DEBUG
        NSMutableString *log = [NSMutableString stringWithString:@"will remove controller :"];
        for (NSString *vcName in self.removeControllerNameArray) {
            [log appendFormat:@"%@,",vcName];
        }
        CLog(@"%@",log);
#endif
      [self.navigationController removeViewControllerWithArrayName:self.removeControllerNameArray];
    }
    #if DEBUG
     CLog(@"%@ alloc",NSStringFromClass([self class]));
    #endif
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc{
    LogDealloc
}



- (void)backItemClick{
    if (self.navigationController){
        [self.navigationController popViewControllerAnimated:YES];
    }
}


- (void)setLeftBarButton{
    if (self.navigationController) {
       UIButton *backButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 40, 40)];
        [backButton setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
        [backButton addTarget:self action:@selector(backItemClick) forControlEvents:UIControlEventTouchUpInside];
        UIBarButtonItem *backItem = [[UIBarButtonItem alloc]initWithCustomView:backButton];
        //覆盖返回按键
        self.navigationItem.leftBarButtonItem = backItem;
        self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];;
    }
}

#pragma mark - tableview

- (TableViewDataExtend *)tableDataExtend{
    if (!_tableDataExtend) {
        _tableDataExtend = [TableViewDataExtend dataWithPageNum:1 pageSize:15];
    }
    return _tableDataExtend;
}

- (void)showNoContentImageView:(NSString *)tipMsg{
    [self.noContentImgV setHidden:NO];
    [self.view addSubview:self.noContentImgV];
    [self.noContentImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.centerY.equalTo(self.view.mas_centerY).offset(-40);
        make.height.equalTo(@81);
        make.width.equalTo(@81);
    }];
    
    [self.view addSubview:self.statusTextView];
//    if ([tipMsg containsString:@";"]) {
//        NSArray *msgArray = [tipMsg componentsSeparatedByString:@";"];
//        NSString *tipStr = [msgArray objectAtIndex:1];
//        NSString *content = [tipMsg stringByReplacingOccurrencesOfString:@";" withString:@""];
//        self.statusTextView.text = content;
//        NSDictionary *attributes = @{NSFontAttributeName:PingFangZhongChangGuiForFont(14),
//                                     NSForegroundColorAttributeName:kGrayColor};
//        NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:_statusTextView.text attributes:attributes];
//        [attributedString addAttribute:NSLinkAttributeName
//                                 value:@"tapClick://"
//                                 range:[[attributedString string] rangeOfString:tipStr]];
//        self.statusTextView.attributedText = attributedString;
//    }else{
//        self.statusTextView.text = tipMsg;
//    }
    self.statusTextView.text = @"暂无内容~";
    [self.statusTextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.top.equalTo(self.noContentImgV.mas_bottom).offset(10);
    }];

    
    
//    [self.view addSubview:self.tipLabel];
//    if ([tipMsg containsString:@";"]) {
//
//    }else{
//        self.tipLabel.text = tipMsg;
//    }
//    [self.tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerX.equalTo(self.view);
//        make.top.equalTo(self.noContentImgV.mas_bottom).offset(10);
//    }];
}

- (void)hidenNoContentImageView{
    [self.noContentImgV setHidden:YES];
    [self.noContentImgV removeFromSuperview];
    [self.statusTextView removeFromSuperview];
}

#pragma mark - UITextViewDelegate

- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange {
    if ([[URL scheme] isEqualToString:@"tapClick"]) {
        self.tabBarController.selectedIndex = 0;
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
    return YES;
}


//- (void)setNavigationBarColor:(){
//    
//}
//
//-(void)viewWillAppear:(BOOL)animated{
//    [super viewWillAppear:animated];
//    self.temptitleTextAttributes = self.navigationController.navigationBar.titleTextAttributes;
//    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName: [UIFont systemFontOfSize:18]}];
//    
//    [self.navigationItem.rightBarButtonItem setTintColor:[UIColor whiteColor]];
//    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithHexString:@"#419ae1"]]
//     
//                                                 forBarPosition:UIBarPositionAny
//     
//                                                     barMetrics:UIBarMetricsDefault];
//    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
//    [self.navigationController.navigationBar setShadowImage:[UIImage new]];
//}
//
//
//- (void)viewWillDisappear:(BOOL)animated{
//    [super viewWillDisappear:animated];
//    
//    self.navigationController.navigationBar.titleTextAttributes = self.temptitleTextAttributes;
//    [self.navigationItem.rightBarButtonItem setTintColor:[UIColor blackColor]];
//    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithHexString:@"0xffffff"]]
//                                                 forBarPosition:UIBarPositionAny
//                                                     barMetrics:UIBarMetricsDefault];
//    self.navigationController.navigationBar.tintColor = [UIColor blackColor];
//    //  [self.navigationController.navigationBar setShadowImage:[UIImage imageWithColor:[UIColor colorWithHexString:@"#dfdfdf"]]];
//    [self.navigationController.navigationBar setShadowImage:nil];
//}



- (UITextView *)statusTextView{
    if(!_statusTextView){
        _statusTextView =  [[UITextView alloc]init];
        
        _statusTextView.backgroundColor = kAppBackgoundColor;
        _statusTextView.textColor = kGrayColor;
        _statusTextView.font = PingFangZhongChangGuiForFont(14);
        _statusTextView.editable = NO;
        _statusTextView.delegate = self;
        _statusTextView.scrollEnabled = NO;
        
        _statusTextView.linkTextAttributes = @{ NSForegroundColorAttributeName: [UIColor colorWithRGB:0x4979E6]};
    }
    return _statusTextView;
}


MACRO_UIImageView_Lazyload(noContentImgV,@"NoContent")
MACRO_UILabel_LazyloadNoTextWithPFCGFont(tipLabel, kGrayColor, 13)



@end
